﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace YXShop.Web.membercenter.shop.shop_product
{
    public partial class product_edit : System.Web.UI.Page
    {
        YXShop.BLL.Product.Productclass bll = new YXShop.BLL.Product.Productclass();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                this.txtContentPageTemplate.Attributes.Add("onclick", "GetFile(this)");
                this.txtContentPageTemplate.Attributes.Add("readonly", "readonly");
                GetFileList();

                if (Request.Form["Option"] != null && !Request.Form["Option"].Trim().Equals("")
                && Request.Form["ID"] != null && !Request.Form["ID"].Trim().Equals(""))
                {
                    string types = Request.Form["Option"].Trim();
                    if (types == "first")
                    {
                        int id = Convert.ToInt32(Request.Form["ID"].Trim());
                        Response.Write(secondClass(id, ""));
                    }
                    else if (types == "Secondarry")
                    {
                        int id = Convert.ToInt32(Request.Form["ID"].Trim());
                        Response.Write(thirdClass(id, ""));
                    }
                    else if (types == "thirdarry")
                    {
                        int id = Convert.ToInt32(Request.Form["ID"].Trim());
                        Response.Write(fourClass(id, ""));
                    }
                    else if (types == "Vali")
                    {
                        int id = Convert.ToInt32(Request.Form["ID"].Trim());
                        Vali(id);
                    }
                    else if (types == "Brand")
                    {
                        string id = Convert.ToString(Request.Form["ID"].Trim());
                        Response.Write(BrandList(id, ""));
                    }
                    else if (types == "Property")
                    {
                        string id = Convert.ToString(Request.Form["ID"].Trim());
                        Response.Write(bindProperty(id, ""));
                    }
                    else if (types == "delAlbum")
                    {
                        string id = Convert.ToString(Request.Form["ID"].Trim());
                        DelAlbum(id);
                    }
                    Response.End();
                    return;
                }
                else if (Request.Form["Option"] != null && !Request.Form["Option"].Trim().Equals("")
                && Request.Form["Name"] != null && !Request.Form["Name"].Trim().Equals(""))
                {
                    string Name = Request.Form["Name"].ToString();
                    string types = Request.Form["Option"].Trim();
                    if (types == "SearchProduct")
                    {
                        SearchRelatedProduct(Name);
                    }
                    else if (types == "SearchAtricle")
                    {
                        SearchRelatedArticle(Name);
                    }
                    Response.End();
                    return;
                }
                this.ltRelatingProductSelected.Text = "<select name=\"selPro_RelatingProIDSelect\" size=\"14\" multiple=\"multiple\" style=\"width: 98%\"></select>";
                this.ltRelatingArticle.Text = "<select name=\"selPro_RelatingArtIDSelect\" size=\"14\" multiple=\"multiple\" style=\"width: 98%\"></select>";
                if (ChangeHope.WebPage.PageRequest.GetInt("cid") > 0)
                {
                    string CID = ChangeHope.WebPage.PageRequest.GetQueryString("cid");
                    this.ltaBrand.Text = BrandList(CID, "");
                    this.ltaProperty.Text = bindProperty(CID, "");
                    AllBindProductClass(CID);
                    this.hfProductClassID.Value = CID;
                }
                if (ChangeHope.WebPage.PageRequest.GetInt("id") > 0)
                {
                    string CID = ChangeHope.WebPage.PageRequest.GetQueryString("cid");
                    bindInfo(CID, ChangeHope.WebPage.PageRequest.GetInt("id"));
                }
                else
                {
                    bindUnit("");
                    this.ltaMemberMank.Text = BindRank("");
                }
                InitWebControl();
            }
        }

        private void GetFileList()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            ChangeHope.Common.FileHelper file = new ChangeHope.Common.FileHelper();

            StringBuilder filelist = new StringBuilder();
            file.rootUrl = Server.MapPath("~/" + sp.WebSiteTemplatePath);
            file.listFiles(file.rootUrl, 0);

            filelist.AppendLine("<script type=\"text/javascript\">");
            filelist.AppendLine("d = new dTree('d');");
            filelist.AppendLine("d.add(0,-1,'请选择模版');");
            filelist.AppendLine(file.fileTree.ToString());
            filelist.AppendLine("document.write(d);");
            filelist.AppendLine("$(\"fileLists\").style.visibility=\"hidden\";");
            filelist.AppendLine("</script>");
            this.ltlFileList.Text = filelist.ToString();
            file = null;
        }



        #region 绑定产品分类

        #region 绑定所有分类
        protected void AllBindProductClass(string cid)
        {
            YXShop.BLL.Product.Productclass bll = new YXShop.BLL.Product.Productclass();
            YXShop.Model.Product.Productclass model = bll.GetModelID(int.Parse(cid));
            if (model != null)
            {
                string[] Parentpath = (model.Parentpath + "," + cid).Split(',');
                if (Parentpath.Length >= 1)
                {
                    this.lrafirstClass.Text = ClassList(0, Parentpath[1].ToString());
                }
                else
                {
                    this.lrafirstClass.Text = ClassList(0, "");
                }
                if (Parentpath.Length > 2)
                {
                    this.lrasecondClass.Text = secondClass(int.Parse(Parentpath[1].ToString()), Parentpath[2].ToString());
                }
                else
                {
                    this.lrasecondClass.Text = "<select size=\"18\" style=\"width: 180px\"></select>";
                }
                if (Parentpath.Length > 3)
                {
                    this.lrathirdClass.Text = thirdClass(int.Parse(Parentpath[2].ToString()), Parentpath[3].ToString());
                }
                else
                {
                    this.lrathirdClass.Text = "<select size=\"18\" style=\"width: 180px\"></select>";
                }
                if (Parentpath.Length > 4)
                {
                    this.lratfourClass.Text = fourClass(int.Parse(Parentpath[3].ToString()), Parentpath[Parentpath.Length - 1].ToString());
                }
                else
                {
                    this.lratfourClass.Text = "<select size=\"18\" style=\"width: 180px\"></select>";
                }

            }
        }
        #endregion

        #region 绑定一级分类
        /// <summary>
        /// 绑定一级分类
        /// </summary>
        /// <param name="CID"></param>
        protected string ClassList(int CID, string selcid)
        {

            DataTable dt = bll.GetFatherList(CID);
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select id=\"firstClass\" name=\"firstClass\" size=\"18\"  style=\"width:180px\" onchange=\"firstarry(this.value);OptionValue(this.value);\">");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (selcid == dt.Rows[i]["cid"].ToString())
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " selected=\"selected\" >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                    else
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                }
            }
            shtml.Append("</select>");
            return shtml.ToString();
        }
        #endregion

        #region 绑定二级分类
        private string secondClass(int CID, string selcid)
        {
            DataTable dt = bll.GetFatherList(CID);
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select id=\"secondClass\" name=\"secondClass\" size=\"18\"  style=\"width:180px\" onchange=\"Secondarry(this.value);OptionValue(this.value);\">");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (selcid == dt.Rows[i]["cid"].ToString())
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " selected=\"selected\" >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                    else
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                }
            }
            shtml.Append("</select>");
            return shtml.ToString();
        }
        #endregion

        #region 绑定三级分类
        private string thirdClass(int CID, string selcid)
        {
            DataTable dt = bll.GetFatherList(CID);
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select id=\"thirdClass\" name=\"thirdClass\" size=\"18\"  style=\"width:180px\" onchange=\"thirdarry(this.value);OptionValue(this.value);\">");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (selcid == dt.Rows[i]["cid"].ToString())
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " selected=\"selected\" >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                    else
                    {
                        shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " >" + dt.Rows[i]["name"].ToString() + "</option>");
                    }
                }
            }
            shtml.Append("</select>");
            return shtml.ToString();
        }
        #endregion

        #region 绑定四级及以下分类
        private string fourClass(int CID, string selcid)
        {
            string KG = "";
            YXShop.Model.Product.Productclass model = bll.GetModelID(CID);
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select id=\"thirdClass\" name=\"thirdClass\" size=\"18\" onchange=\"OptionValue(this.value);\" style=\"width:180px\">");
            if (model != null)
            {
                string ParentPath = model.Parentpath.ToString() + "," + model.ID.ToString();
                DataTable dt = bll.GetBlurList(ParentPath);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        KG = "";
                        string[] Path = dt.Rows[i]["parentpath"].ToString().Split(',');
                        for (int j = 4; j < Path.Length; j++)
                        {
                            KG += "|_&nbsp;&nbsp;";
                        }
                        if (selcid == dt.Rows[i]["cid"].ToString())
                        {
                            shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " selected=\"selected\" >" + KG + dt.Rows[i]["name"].ToString() + "</option>");
                        }
                        else
                        {
                            shtml.Append("<option value=" + dt.Rows[i]["cid"].ToString() + " >" + KG + dt.Rows[i]["name"].ToString() + "</option>");
                        }
                    }
                }
            }
            shtml.Append("</select>");
            return shtml.ToString();
        }
        #endregion

        #region 验证产品分类是否是最后一级
        private void Vali(int CID)
        {
            DataTable dt = bll.GetFatherList(CID);
            if (dt.Rows.Count > 0)
            {
                Response.Write("true");
            }
            else
            {
                Response.Write("false");
            }
        }
        #endregion


        #endregion

        #region 添加与编辑
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["MemberID"]!=null)
            {
                Save();
            }
          
        }
        protected void Save()
        {
            YXShop.BLL.Product.ProductInfo bllInfo = new YXShop.BLL.Product.ProductInfo();
            YXShop.Model.Product.ProductInfo model = new YXShop.Model.Product.ProductInfo();
            model.pro_Property = PropertyValue();
            model.pro_CID = this.hfProductClassID.Value != string.Empty ? this.hfProductClassID.Value : "0";
            model.pro_BrandID = ChangeHope.WebPage.PageRequest.GetFormInt("selBrand");
            model.pro_Name = this.txtName.Text.Trim();
            model.pro_Templates = "";
            //model.pro_Model = this.txtModel.Text.Trim();
            model.pro_NO = this.txtNo.Text.Trim();
            model.pro_ContentTemplate = this.txtContentPageTemplate.Text.Trim();
            model.pro_KeyWord = this.txtKey.Text.Trim();
            model.pro_ShopPrice = this.txtShopPrice.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtShopPrice.Text.Trim()) : 0;
            model.pro_MarketPrice = this.txtCostPrice.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtCostPrice.Text.Trim()) : 0;
            model.pro_RatingDiscount = MemberMank();
            model.pro_EPoints = this.txtStamp.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtStamp.Text.Trim()) : 0;
            model.pro_DonateIntegral = this.txtDonateInteg.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtDonateInteg.Text.Trim()) : 0;
            //图片参数
            YXShop.Common.SysParameter sys = new YXShop.Common.SysParameter();
            bool WhetherWater = sys.IsWatermark;
            string OriginalThumbnailSavePath = "/yxuploadfile/product/originalthumbnail";
            string OriginalSavePath = "/yxuploadfile/product/original";
            string ThumbnailSavePath = "/yxuploadfile/product/thumbnail";
            int ThumbnailsHeight = sys.ThumbnailsHeight;
            int ThumbnailsWidth = sys.ThumbnailsWidth;
            int ImagesThumbnailsHeight = sys.ImagesThumbnailsHeight;
            int ImagesThumbnailsWidth = sys.ImagesThumbnailsWidth;
            int TextWatermarkTransparent = sys.TextWatermarkTransparent;
            int ImageWatermarkTransparent = sys.ImageWatermarkTransparent;
            string TextOrImagesWatermark = sys.TextOrImagesWatermark;
            string WatermarkText = sys.WatermarkText;
            string WatermarkImage = sys.WatermarkImage;
            string WatermarkPosition = sys.WatermarkPosition;
            string Original = string.Empty;
            string OriginalThumbnails = string.Empty;
            string ThumbnailsImage = string.Empty;
            ChangeHope.Common.UploadProcesedImages wm = new ChangeHope.Common.UploadProcesedImages();

            #region 上传图品详细图
            if (fuPic.HasFile)
            {
                //原图
                ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile();
                uf.ExtensionLim = ".gif,.jpg,.jpeg,.dmp";
                uf.FileLengthLim = 4000;
                uf.PostedFile = this.fuPic;
                uf.SavePath = OriginalSavePath;
                if (uf.Upload())
                {
                    if (uf.HaveLoad)
                    {
                        Original = uf.FilePath;
                        //原图缩略图
                        wm.SourceImagePath = Original;
                        wm.ThumbnailImagePath = OriginalThumbnailSavePath;
                        wm.ThumbnailImageWidth = ImagesThumbnailsWidth;
                        wm.ThumbnailImageHeight = ImagesThumbnailsHeight;
                        if (wm.ToThumbnailImage())
                        {
                            OriginalThumbnails = wm.FilePath;
                        }
                        else
                        {
                            this.ltlMsg.Text = "操作失败，" + wm.Message + "";
                            this.pnlMsg.Visible = true;
                            this.pnlMsg.CssClass = "actionOk";
                            return;
                        }

                    }
                }
                else
                {
                    this.ltlMsg.Text = "操作失败，" + uf.Message + "";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionOk";
                    return;
                }
                if (WhetherWater)
                {
                    //原图水印
                    if (!string.IsNullOrEmpty(Original))
                    {
                        wm.SourceImagePath = Original;
                        wm.ImageDeaphaneity = float.Parse(ImageWatermarkTransparent.ToString());
                        wm.Diaphaneity = TextWatermarkTransparent;
                        switch (WatermarkPosition)
                        {
                            case "1":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftTop;
                                break;
                            case "2":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftBottom;
                                break;
                            case "3":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightTop;
                                break;
                            case "4":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightBottom;
                                break;
                            case "5":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterTop;
                                break;
                            case "9":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.Center;
                                break;
                            case "7":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterBottom;
                                break;
                        }
                        if (TextOrImagesWatermark == "0")
                        {
                            //图片水印
                            if (!string.IsNullOrEmpty(WatermarkImage))
                            {
                                wm.WaterMarkImagePath = WatermarkImage;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印图片是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        else
                        {
                            //文字水印
                            if (!string.IsNullOrEmpty(WatermarkText))
                            {
                                wm.WaterMarkText = WatermarkText;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印文字是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        wm.SaveWaterMarkImagePath = OriginalSavePath;
                        if (wm.ToWaterMark())
                        {
                            Original = wm.FilePath;
                        }
                        else
                        {
                            this.ltlMsg.Text = "操作失败，" + wm.Message + "";
                            this.pnlMsg.Visible = true;
                            this.pnlMsg.CssClass = "actionOk";
                            return;
                        }
                    }
                    //原图缩略图水印
                    if (!string.IsNullOrEmpty(OriginalThumbnails))
                    {
                        wm.SourceImagePath = OriginalThumbnails;
                        wm.ImageDeaphaneity = float.Parse(ImageWatermarkTransparent.ToString());
                        wm.Diaphaneity = TextWatermarkTransparent;
                        switch (WatermarkPosition)
                        {
                            case "1":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftTop;
                                break;
                            case "2":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftBottom;
                                break;
                            case "3":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightTop;
                                break;
                            case "4":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightBottom;
                                break;
                            case "5":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterTop;
                                break;
                            case "9":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.Center;
                                break;
                            case "7":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterBottom;
                                break;
                        }
                        if (TextOrImagesWatermark == "0")
                        {
                            //图片水印
                            if (!string.IsNullOrEmpty(WatermarkImage))
                            {
                                wm.WaterMarkImagePath = WatermarkImage;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印图片是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        else
                        {
                            //文字水印
                            if (!string.IsNullOrEmpty(WatermarkText))
                            {
                                wm.WaterMarkText = WatermarkText;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印文字是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        wm.SaveWaterMarkImagePath = OriginalThumbnailSavePath;
                        if (wm.ToWaterMark())
                        {
                            OriginalThumbnails = wm.FilePath;
                        }
                        else
                        {
                            this.ltlMsg.Text = "操作失败，" + wm.Message + "";
                            this.pnlMsg.Visible = true;
                            this.pnlMsg.CssClass = "actionOk";
                            return;
                        }
                    }

                }
                //自动生成商品缩略图
                if (this.cbBreviary.Checked)
                {
                    wm.SourceImagePath = Original;
                    wm.ThumbnailImagePath = ThumbnailSavePath;
                    wm.ThumbnailImageWidth = Convert.ToInt32(ThumbnailsWidth);
                    wm.ThumbnailImageHeight = Convert.ToInt32(ThumbnailsHeight);
                    if (wm.ToThumbnailImage())
                    {
                        ThumbnailsImage = wm.FilePath;
                    }
                    else
                    {
                        this.ltlMsg.Text = "操作失败，" + wm.Message + "";
                        this.pnlMsg.Visible = true;
                        this.pnlMsg.CssClass = "actionOk";
                        return;
                    }
                }
            }
            else
            {
                if (ViewState["ID"] != null)
                {
                    if (ViewState["pro_Thumbnail"] != null)
                    {
                        ThumbnailsImage = ViewState["pro_Thumbnail"].ToString();
                    }
                    if (ViewState["pro_Original"] != null)
                    {
                        Original = ViewState["pro_Original"].ToString();
                    }
                    if (ViewState["pro_Images"] != null)
                    {
                        OriginalThumbnails = ViewState["pro_Images"].ToString();
                    }
                }
            }
            #endregion

            #region 上传缩略图
            if (fuSmallImages.HasFile && !cbBreviary.Checked)
            {
                ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile();
                uf.ExtensionLim = ".gif,.jpg,.jpeg,.dmp";
                uf.FileLengthLim = 4000;
                uf.PostedFile = this.fuSmallImages;
                uf.SavePath = ThumbnailSavePath;
                if (uf.Upload())
                {
                    if (uf.HaveLoad)
                    {
                        ThumbnailsImage = uf.FilePath;
                    }
                }
                else
                {
                    this.ltlMsg.Text = "操作失败，" + uf.Message + "";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionOk";
                    return;
                }
                if (WhetherWater)
                {
                    if (!string.IsNullOrEmpty(ThumbnailsImage))
                    {
                        wm.SourceImagePath = ThumbnailsImage;
                        wm.ImageDeaphaneity = ImageWatermarkTransparent;
                        wm.Diaphaneity = TextWatermarkTransparent;
                        switch (WatermarkPosition)
                        {
                            case "1":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftTop;
                                break;
                            case "2":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftBottom;
                                break;
                            case "3":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightTop;
                                break;
                            case "4":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightBottom;
                                break;
                            case "5":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterTop;
                                break;
                            case "9":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.Center;
                                break;
                            case "7":
                                wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterBottom;
                                break;
                        }
                        if (TextOrImagesWatermark == "0")
                        {
                            //图片水印
                            if (!string.IsNullOrEmpty(WatermarkImage))
                            {
                                wm.WaterMarkImagePath = WatermarkImage;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印图片是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        else
                        {
                            //文字水印
                            if (!string.IsNullOrEmpty(WatermarkText))
                            {
                                wm.WaterMarkText = WatermarkText;
                            }
                            else
                            {
                                this.ltlMsg.Text = "操作失败，上传图片水印失败，请确认系统设置水印文字是否存在。";
                                this.pnlMsg.Visible = true;
                                this.pnlMsg.CssClass = "actionOk";
                                return;
                            }
                        }
                        wm.SaveWaterMarkImagePath = ThumbnailSavePath;
                        if (wm.ToWaterMark())
                        {
                            ThumbnailsImage = wm.FilePath;
                        }
                        else
                        {
                            this.ltlMsg.Text = "操作失败，" + wm.Message + "";
                            this.pnlMsg.Visible = true;
                            this.pnlMsg.CssClass = "actionOk";
                            return;
                        }
                    }
                }
            }
            else
            {
                if (ViewState["ID"] != null)
                {
                    if (ViewState["pro_Thumbnail"] != null && ViewState["pro_Thumbnail"].ToString() != string.Empty)
                    {
                        ThumbnailsImage = ViewState["pro_Thumbnail"].ToString();
                    }
                }
            }
            #endregion

            model.pro_Original = Original;
            model.pro_Images = OriginalThumbnails;
            model.pro_Thumbnail = ThumbnailsImage;
            model.pro_Synopsis = this.txtDescription.Text;
            model.pro_Content = this.txtContent.Value;
            model.pro_MetaKeywords = this.txtOptimizationKey.Text;
            model.pro_MetaDescription = this.txtOptimizationDescription.Text;
            model.pro_MetaTitle = this.txtOptimizationtitle.Text;
            model.pro_Weight = this.txtWeight.Text != string.Empty ? Convert.ToDecimal(this.txtWeight.Text) : 0;
            model.pro_WeightUnit = this.ddlWeightUnit.SelectedValue != string.Empty ? Convert.ToInt32(this.ddlWeightUnit.SelectedValue) : 0;
            if (!ChangeHope.Common.ValidateHelper.IsDecimal(this.txtShopPrice.Text))
            {
                this.ltlMsg.Text = "操作失败，价格输入错误！";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            if(!ChangeHope.Common.ValidateHelper.IsNumber(this.txtStock.Text))
            {
                this.ltlMsg.Text = "操作失败，库存请输入数字";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            if (!ChangeHope.Common.ValidateHelper.IsNumber(this.txtUpCount.Text))
            {
                this.ltlMsg.Text = "操作失败，上架数量请输入数字";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            if(Convert.ToInt32(this.txtUpCount.Text)>Convert.ToInt32(this.txtStock.Text))
            {
                this.ltlMsg.Text = "操作失败，上架数量大于库存数量";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            model.pro_Stock = Convert.ToInt32(this.txtStock.Text.Trim());
            model.pro_Unit = ChangeHope.WebPage.PageRequest.GetFormString("selUnit");
            model.pro_Alarm = this.txtAlarmCount.Text != string.Empty ? int.Parse(this.txtAlarmCount.Text) : 0;
            model.pro_AuditCount = Convert.ToInt32(this.txtUpCount.Text);
            model.pro_Audit = Convert.ToInt32(this.rblIsFiling.SelectedValue);
            #region 商品状态：推荐商品|热卖商品|特价商品|活动专区|最新商品|首页显示
            string Pro_State = "";
            for (int i = 0; i < this.chklstState.Items.Count; i++)
            {
                if (chklstState.Items[i].Selected)
                {
                    Pro_State += "1|";
                }
                else
                {
                    Pro_State += "0|";
                }
            }
            #endregion
            model.pro_State = Pro_State;
            #region 商品标识：团购|拍卖|批发
            string Pro_Designation = "";
            for (int j = 0; j < this.chklstMarking.Items.Count; j++)
            {
                if (chklstMarking.Items[j].Selected)
                {
                    Pro_Designation += "1|";
                }
                else
                {
                    Pro_Designation += "0|";
                }
            }
            #endregion
            model.pro_Designation = Pro_Designation;
            model.pro_RelatingArtID = ChangeHope.WebPage.PageRequest.GetFormString("selPro_RelatingArtIDSelect");
            model.pro_RelatingproID = ChangeHope.WebPage.PageRequest.GetFormString("selPro_RelatingProIDSelect");
            model.pro_CreateTime = System.DateTime.Now;
            model.pro_UpdateTime = System.DateTime.Now;
            model.pro_OnClicks = this.txtOnClick.Text != string.Empty ? int.Parse(this.txtOnClick.Text.Trim()) : 0;
            model.pro_IsAllowComment = Convert.ToInt32(this.rblIsAllowComment.SelectedValue);
            model.pro_SaleNum = 0;
            model.pro_CostPrice = this.txtCostPrice.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtCostPrice.Text.Trim()) : 0;
            model.pro_AutoUp = this.txtFilingTime.Text.Trim() != string.Empty ? Convert.ToDateTime(this.txtFilingTime.Text.Trim()) : System.DateTime.Now;
            model.pro_AutoDown = this.txtDownTime.Text.Trim() != string.Empty ? Convert.ToDateTime(this.txtDownTime.Text.Trim()) : System.DateTime.Now;
            model.pro_IsAuto = Convert.ToInt32(this.rdolstIsAuto.SelectedValue);
            model.pro_SaleType = Convert.ToInt32(this.ddlSaleType.SelectedValue);
            model.pro_IntegralPrice = this.txtIntegral.Text.Trim() != string.Empty ? Convert.ToDecimal(this.txtIntegral.Text) : 0;
            model.pro_Area = this.hfid.Value != string.Empty ? this.hfid.Value : "0";
            model.pro_PutoutID = Convert.ToInt32(Session["MemberID"]);
            model.pro_PutoutType = 1;
            //model.pro_Templates = this.txtCategoryTemplates.Text;

            if (ViewState["ID"] != null)
            {
                model.pro_ID = Convert.ToInt32(ViewState["ID"].ToString());
                string AlbumInfo = Album(ImagesThumbnailsWidth, ImagesThumbnailsHeight, WhetherWater, ImageWatermarkTransparent, TextWatermarkTransparent, WatermarkPosition, WatermarkImage, WatermarkText, TextOrImagesWatermark, true, Convert.ToInt32(ViewState["ID"].ToString()));
                bllInfo.Update(model);
                this.ltlMsg.Text = "操作成功，您的以修改该商品信息。" + AlbumInfo;
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionOk";
            }
            else
            {
                string AlbumInfo = Album(ImagesThumbnailsWidth, ImagesThumbnailsHeight, WhetherWater, ImageWatermarkTransparent, TextWatermarkTransparent, WatermarkPosition, WatermarkImage, WatermarkText, TextOrImagesWatermark, false, 0);
                bllInfo.Add(model);
                this.ltlMsg.Text = "操作成功，您的添加的商品信息以保存。" + AlbumInfo;
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionOk";
                this.txtName.Text = string.Empty;


            }
        }

        #region 获取属性值
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <returns></returns>
        protected string PropertyValue()
        {
            string Pro_PValues = string.Empty;
            string parmTemp = ChangeHope.WebPage.PageRequest.GetFormString("ProPropertyID");
            if (parmTemp.IndexOf(",") > -1)
            {
                foreach (string pTemp in parmTemp.Split(','))
                {
                    string PropertyDataValue = ChangeHope.WebPage.PageRequest.GetFormString(pTemp);
                    string PropertyDataID = pTemp;
                    if (!string.IsNullOrEmpty(PropertyDataValue))
                    {
                        Pro_PValues += PropertyDataID + "," + PropertyDataValue + "|";
                    }
                }
            }
            else
            {
                string PropertyDataValue = ChangeHope.WebPage.PageRequest.GetFormString(parmTemp);
                string PropertyDataID = parmTemp;
                if (!string.IsNullOrEmpty(PropertyDataValue))
                {
                    Pro_PValues += PropertyDataID + "," + PropertyDataValue + "|";
                }
            }
            return Pro_PValues;
        }
        #endregion

        #region 获取会员等级价
        /// <summary>
        /// 获取会员等级价
        /// </summary>
        /// <returns></returns>
        protected string MemberMank()
        {
            string Prics = string.Empty;
            string MemberMankShopPrice = ChangeHope.WebPage.PageRequest.GetFormString("txtPro_RatingDiscount");
            string MemberMankID = ChangeHope.WebPage.PageRequest.GetFormString("RatingID");
            if (!string.IsNullOrEmpty(MemberMankID))
            {
                string[] arryMemberMankID = MemberMankID.Split(',');
                string[] arryMemberMankShopPrice = MemberMankShopPrice.Split(',');
                for (int i = 0; i < arryMemberMankID.Length; i++)
                {
                    if (arryMemberMankShopPrice[i] != string.Empty)
                    {
                        Prics += arryMemberMankID[i] + "," + arryMemberMankShopPrice[i] + "|";
                    }
                }
            }
            return Prics;
        }
        #endregion

        #region 商品相册
        /// <summary>
        /// 上传商品相册图
        /// </summary>
        /// <param name="albumthumbnail"></param>
        /// <param name="ImagesThumbnailsWidth"></param>
        /// <param name="ImagesThumbnailsHeight"></param>
        /// <param name="WhetherWater"></param>
        /// <param name="ImageWatermarkTransparent"></param>
        /// <param name="TextWatermarkTransparent"></param>
        /// <param name="WatermarkPosition"></param>
        /// <param name="WatermarkImage"></param>
        /// <param name="WatermarkText"></param>
        /// <param name="TextOrImagesWatermark"></param>
        protected string Album(int ImagesThumbnailsWidth, int ImagesThumbnailsHeight, bool WhetherWater, int ImageWatermarkTransparent, int TextWatermarkTransparent, string WatermarkPosition, string WatermarkImage, string WatermarkText, string TextOrImagesWatermark, bool IsModfiy, int ProductId)
        {
            string gomessage = "";
            int proId = 0;
            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            if (IsModfiy)
            {
                proId = ProductId;
            }
            else
            {
                if (bll.GetMax() == 0)
                {
                    return gomessage = "相册上传失败";
                }
                else
                {
                    proId = bll.GetMax() + 1;
                }
            }
            System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
            System.Text.StringBuilder strmsg = new System.Text.StringBuilder("");
            YXShop.BLL.Product.ProductAlbum pabll = new YXShop.BLL.Product.ProductAlbum();
            YXShop.Model.Product.ProductAlbum pamodel = new YXShop.Model.Product.ProductAlbum();
            string[] rd = null;
            string des = ChangeHope.WebPage.PageRequest.GetFormString("description");
            if (!string.IsNullOrEmpty(des))
            {
                rd = des.Split(',');//获得图片描述的文本框字符串数组，为对应的图片的描述
            }
            if (strmsg.Length <= 0)//说明图片大小和格式都没问题
            {
                YXShop.BLL.Product.ProductAlbum PGBLL = new YXShop.BLL.Product.ProductAlbum();
                YXShop.Model.Product.ProductAlbum PGModel = new YXShop.Model.Product.ProductAlbum();
                int autouFile = 0;
                if (cbBreviary.Checked)//如果自动生成缩略图被选中，那么商品相册的fileupload集合从索引1开始计算，否则从2开始计算
                {
                    autouFile = files.Count;
                }
                else
                {
                    autouFile = files.Count;
                }
                ChangeHope.Common.UploadProcesedImages wm = new ChangeHope.Common.UploadProcesedImages();
                ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile();
                string AlbumThumbnailSave = "yxuploadfile/product/albumthumbnail";
                string AlbumOriginalSave = "yxuploadfile/product/albumoriginal";
                string AlbumThumbnail = string.Empty;
                string AlbumOriginal = string.Empty;
                string Message = string.Empty;
                uf.ExtensionLim = ".gif,.jpg,.jpeg,.dmp";
                uf.FileLengthLim = 4000;
                for (int i = 2; i < files.Count; i++)
                {
                    uf.MyFile = files[i];
                    uf.SavePath = AlbumOriginalSave;
                    if (uf.HTMLUpLoad())
                    {
                        if (uf.HaveLoad)
                        {
                            AlbumOriginal = uf.FilePath;
                            //原图缩略图
                            wm.SourceImagePath = AlbumOriginal;
                            wm.ThumbnailImagePath = AlbumOriginalSave;
                            wm.ThumbnailImageWidth = ImagesThumbnailsWidth;
                            wm.ThumbnailImageHeight = ImagesThumbnailsHeight;
                            if (wm.ToThumbnailImage())
                            {
                                AlbumThumbnail = wm.FilePath;
                            }
                            else
                            {
                                gomessage += "<br>" + wm.Message;

                            }


                        }
                        else
                        {
                            gomessage += "<br>" + uf.Message;
                        }
                        if (WhetherWater)
                        {
                            //原图水印
                            if (!string.IsNullOrEmpty(AlbumOriginal))
                            {
                                wm.SourceImagePath = AlbumOriginal;
                                wm.ImageDeaphaneity = float.Parse(ImageWatermarkTransparent.ToString());
                                wm.Diaphaneity = TextWatermarkTransparent;
                                switch (WatermarkPosition)
                                {
                                    case "1":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftTop;
                                        break;
                                    case "2":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftBottom;
                                        break;
                                    case "3":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightTop;
                                        break;
                                    case "4":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightBottom;
                                        break;
                                    case "5":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterTop;
                                        break;
                                    case "9":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.Center;
                                        break;
                                    case "7":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterBottom;
                                        break;
                                }
                                if (TextOrImagesWatermark == "0")
                                {
                                    //图片水印
                                    if (!string.IsNullOrEmpty(WatermarkImage))
                                    {
                                        wm.WaterMarkImagePath = WatermarkImage;
                                    }
                                    else
                                    {
                                        gomessage += "<br>" + "操作失败，上传图片水印失败，请确认系统设置水印图片是否存在。";
                                    }
                                }
                                else
                                {
                                    //文字水印
                                    if (!string.IsNullOrEmpty(WatermarkText))
                                    {
                                        wm.WaterMarkText = WatermarkText;
                                    }
                                    else
                                    {
                                        gomessage += "<br>" + "操作失败，上传图片水印失败，请确认系统设置水印文字是否存在。";
                                    }
                                }
                                wm.SaveWaterMarkImagePath = AlbumOriginalSave;
                                if (wm.ToWaterMark())
                                {
                                    AlbumOriginal = wm.FilePath;
                                }
                                else
                                {
                                    gomessage += "<br>" + "操作失败，" + wm.Message + "";
                                }
                            }
                            //原图缩略图水印
                            if (!string.IsNullOrEmpty(AlbumThumbnail))
                            {
                                wm.SourceImagePath = AlbumThumbnail;
                                wm.ImageDeaphaneity = float.Parse(ImageWatermarkTransparent.ToString());
                                wm.Diaphaneity = TextWatermarkTransparent;
                                switch (WatermarkPosition)
                                {
                                    case "1":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftTop;
                                        break;
                                    case "2":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.LeftBottom;
                                        break;
                                    case "3":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightTop;
                                        break;
                                    case "4":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.RightBottom;
                                        break;
                                    case "5":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterTop;
                                        break;
                                    case "9":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.Center;
                                        break;
                                    case "7":
                                        wm.WaterMarkAlign = ChangeHope.Common.ImageAlign.CenterBottom;
                                        break;
                                }
                                if (TextOrImagesWatermark == "0")
                                {
                                    //图片水印
                                    if (!string.IsNullOrEmpty(WatermarkImage))
                                    {
                                        wm.WaterMarkImagePath = WatermarkImage;
                                    }
                                    else
                                    {
                                        gomessage += "<br>" + "操作失败，上传图片水印失败，请确认系统设置水印图片是否存在。";
                                    }
                                }
                                else
                                {
                                    //文字水印
                                    if (!string.IsNullOrEmpty(WatermarkText))
                                    {
                                        wm.WaterMarkText = WatermarkText;
                                    }
                                    else
                                    {
                                        gomessage += "<br>" + "操作失败，上传图片水印失败，请确认系统设置水印文字是否存在。";
                                    }
                                }
                                wm.SaveWaterMarkImagePath = AlbumThumbnailSave;
                                if (wm.ToWaterMark())
                                {
                                    AlbumThumbnail = wm.FilePath;
                                }
                                else
                                {
                                    gomessage += "<br>" + "操作失败，" + wm.Message + "";
                                }
                            }

                        }
                    }
                    pamodel.Productid = proId;
                    pamodel.OriginalAddress = AlbumOriginal;
                    pamodel.ThumbnailAddress = AlbumThumbnail;
                    pamodel.Description = "";
                    pabll.Add(pamodel);
                }

            }
            return gomessage;
        }
        #endregion

        #endregion

        #region 绑定信息
        protected void bindInfo(string cid, int id)
        {
            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            YXShop.Model.Product.ProductInfo model = bll.GetModel(id);
            this.txtArea.Text = AreaName(model.pro_Area);
            this.hfid.Value = model.pro_Area;
            this.ltaBrand.Text = BrandList(cid, model.pro_BrandID.ToString());
            this.txtName.Text = model.pro_Name;
            //this.txtModel.Text = model.pro_Model;
            this.bindUnit(model.pro_Unit);
            this.ddlSaleType.SelectedValue = model.pro_SaleType.ToString();
            if (model.pro_SaleType.ToString() == "2")
            {
                this.trIntegral.Style.Value = "display:";
                this.trShopPrice.Style.Value = "display:none";
            }
            if (model.pro_SaleType.ToString() == "3")
            {
                this.trIntegral.Style.Value = "display:";
            }
            this.txtShopPrice.Text = model.pro_ShopPrice.ToString();
            this.txtIntegral.Text = model.pro_IntegralPrice.ToString();
            this.ltaMemberMank.Text = BindRank(model.pro_RatingDiscount);
            this.txtStock.Text = model.pro_Stock.ToString();
            this.rblIsFiling.SelectedValue = model.pro_Audit.ToString();
            this.txtUpCount.Text = model.pro_AuditCount.ToString();
            this.rdolstIsAuto.SelectedValue = model.pro_IsAuto.ToString();
            this.txtFilingTime.Text = model.pro_AutoUp.ToString();
            this.txtDownTime.Text = model.pro_AutoDown.ToString();
            #region 商品状态：推荐商品|热卖商品|特价商品|活动专区|最新商品|首页显示
            string[] state = model.pro_State.Split('|');
            for (int i = 0; i < state.Length; i++)
            {
                if (state[i] == "1")
                {
                    this.chklstState.Items[i].Selected = true;
                }
            }
            #endregion
            #region 商品标识：团购|拍卖|批发
            string[] Designation = model.pro_Designation.Split('|');
            for (int j = 0; j < Designation.Length; j++)
            {
                if (Designation[j] == "1")
                {
                    this.chklstMarking.Items[j].Selected = true;
                }
            }
            #endregion
            this.txtNo.Text = model.pro_NO;
            this.txtKey.Text = model.pro_KeyWord;
            this.txtMarketPrice.Text = model.pro_CostPrice.ToString();
            this.txtCostPrice.Text = model.pro_MarketPrice.ToString();
            this.txtStamp.Text = model.pro_EPoints.ToString();
            this.txtAlarmCount.Text = model.pro_Alarm.ToString();
            this.txtDonateInteg.Text = model.pro_DonateIntegral.ToString();
            this.txtWeight.Text = model.pro_Weight.ToString();
            this.ddlWeightUnit.SelectedValue = model.pro_WeightUnit.ToString();
            this.txtOnClick.Text = model.pro_OnClicks.ToString();
            this.rblIsAllowComment.SelectedValue = model.pro_IsAllowComment.ToString();
            this.txtDescription.Text = model.pro_Synopsis;
            this.txtContent.Value = model.pro_Content;
            this.ltaProperty.Text = bindProperty(cid, model.pro_Property);
            this.txtOptimizationtitle.Text = model.pro_MetaTitle;
            this.txtOptimizationKey.Text = model.pro_MetaKeywords;
            this.txtOptimizationDescription.Text = model.pro_MetaDescription;
            RelateProductBindInfo(model.pro_RelatingproID);
            RelateArticleBindInfo(model.pro_RelatingArtID);
            bindAlbum(id);
            ViewState["ID"] = model.pro_ID;
            ViewState["pro_Thumbnail"] = model.pro_Thumbnail;
            ViewState["pro_Original"] = model.pro_Original;
            ViewState["pro_Images"] = model.pro_Images;
        }
        #endregion

        #region 绑定区域
        protected string AreaName(string id)
        {
            string[] AreaIdStr = id.Split(',');
            string reStr = "";
            YXShop.BLL.SystemInfo.Provinces bll = new YXShop.BLL.SystemInfo.Provinces();
            for (int i = 0; i < AreaIdStr.Length; i++)
            {
                YXShop.Model.SystemInfo.Provinces model = bll.GetModel(Convert.ToInt32(AreaIdStr[i]));
                if (model != null)
                {
                    if (reStr == "")
                    {
                        reStr = model.CityName;
                    }
                    else
                    {
                        reStr = reStr + "," + model.CityName;
                    }
                }
            }
            return reStr;
        }
        #endregion

        #region 验证
        /// <summary>
        /// 验证
        /// </summary>
        private void InitWebControl()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            this.txtArea.Attributes.Add("readonly", "readonly");
            this.txtArea.Attributes.Add("onclick", "selectFile('Area',new Array(" + this.hfid.ClientID + "," + this.txtArea.ClientID + "),310,450,'" + sp.DummyPaht + "');");
            ChangeHope.WebPage.WebControl.Validate(this.txtName, "输入商品名称的名称", "isnull", "必填", "该项为必填项");

            ChangeHope.WebPage.WebControl.Validate(this.txtShopPrice, "输入商城价格将作为商城销售的价", "ifisfloat", "必填", "该项为必须为数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtStock, "输入商品的库存量", "isint", "必填", "该项为必须为数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtUpCount, "前台商品的可否购买状态取决于您的商品上架数量，可以小于或等于商品库存，请输入正整数", "isint", "必填", "该项为必须为数字");
            ChangeHope.WebPage.WebControl.SetDate(this.txtFilingTime);
            ChangeHope.WebPage.WebControl.SetDate(this.txtDownTime);
            ChangeHope.WebPage.WebControl.Validate(this.txtFilingTime, "商品在前台展示的开始时间", "ifisnull", "选填", "该项为选填项");
            ChangeHope.WebPage.WebControl.Validate(this.txtDownTime, "商品在前台展示的结束是时间", "ifisnull", "选填", "该项为选填项");
            ChangeHope.WebPage.WebControl.Validate(this.txtMarketPrice, "输入市场价格将作为商城价格与市场价格进行对比", "ifisfloat", "选填", "该项为必须为数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtCostPrice, "输入成本价将方便后台管理查看,不会在前台让用户看到该价格", "ifisfloat", "选填", "该项为必须为数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtIntegral, "当您选择了该商品可以使用积分购买时，请输入购买该商品需要支付的积分数,请输入正数", "ifisint", "选填", "该项只能输入数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtStamp, "使用多少点券可以购买该商品，不填写表示该商品不支持点券购买", "ifisint", "选填", "该项只能输入数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtAlarmCount, "输入的报警数量当商品销售到该数量提醒管理员补足该商品", "ifisint", "选填", "该项只能输入数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtDonateInteg, "用户购买该商品否可以获得的积分数，为0表示购买该商品不赠送积分", "ifisint", "选填", "该项只能输入数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtOnClick, "默认查看次数为0，为了使您了解该商品真正的顾客满意度，建议不要修改", "ifisint", "选填", "该项只能输入数字");
            ChangeHope.WebPage.WebControl.Validate(this.txtDescription, "输入信息对商品进行简单的介绍,最多字符不能超过1500个字符", "ifisnull", "选填", "该项为选填项");
            this.Form.Attributes.Add("onsubmit", "return CheckForm()");
        }
        #endregion

        #region 加载品牌
        /// <summary>
        /// 修改商品加载品牌
        /// </summary>
        /// <param name="CID"></param>
        /// <param name="BID"></param>
        protected string BrandList(string CID, string BID)
        {
            YXShop.BLL.Product.ProductBrand bll = new YXShop.BLL.Product.ProductBrand();
            DataTable dt = bll.GetBrandList(CID);
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select name=\"selBrand\" id=\"selBrand\">");
            shtml.Append("<option value=\"0\">--选择品牌--</option>");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                shtml.Append("<option value=\"" + dt.Rows[i]["bid"].ToString() + "\"");
                if (dt.Rows[i]["bid"].ToString() == BID)
                {
                    shtml.Append(" selected=\"selected\" ");
                }
                shtml.Append(">" + dt.Rows[i]["name"].ToString() + "</option>");
            }
            shtml.Append("</select>");
            return shtml.ToString();
        }
        #endregion

        #region 加载商品单位
        protected void bindUnit(string unit)
        {
            YXShop.BLL.Product.ProductUnit bll = new YXShop.BLL.Product.ProductUnit();
            ChangeHope.DataBase.DataByPage dataPage = bll.GetList();
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<select name=\"selUnit\" id=\"selUnit\">");
            shtml.Append("<option value=\"0\" selected=\"selected\">--选择单位--</option>");
            if (dataPage.DataReader != null)
            {

                while (dataPage.DataReader.Read())
                {
                    if (dataPage.DataReader["name"].ToString() == unit)
                    {
                        shtml.Append("<option value=\"" + dataPage.DataReader["name"].ToString() + "\" selected=\"selected\">" + dataPage.DataReader["name"].ToString() + "</option>");
                    }
                    else
                    {
                        shtml.Append("<option value=\"" + dataPage.DataReader["name"].ToString() + " \">" + dataPage.DataReader["name"].ToString() + "</option>");
                    }
                }
                dataPage.Dispose();
                dataPage = null;
            }

            shtml.Append("</select>");
            this.lraUint.Text = shtml.ToString();
        }
        #endregion

        #region 加载会员等级
        /// <summary>
        /// 会员等级价格列表
        /// </summary>
        /// <returns></returns>
        protected string BindRank(string memberPrice)
        {
            string restr = string.Empty;
            YXShop.BLL.Member.MemberRank bll = new YXShop.BLL.Member.MemberRank();
            DataTable dt = bll.GetList();
            if (dt.Rows.Count > 0)
            {
                StringBuilder shtml = new StringBuilder();
                //shtml.Append("<table>");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(memberPrice))
                    {
                        string[] mp = memberPrice.Split('|');
                        string Prices = string.Empty;
                        for (int j = 0; j < mp.Length; j++)
                        {
                            string[] mps = mp[j].ToString().Split(',');
                            if (mps[0].ToString() == dt.Rows[i]["Id"].ToString())
                            {
                                Prices = mps[1].ToString();
                                break;
                            }
                        }
                        shtml.Append("<tr><td  class=\"form_table_input_info\">" + dt.Rows[i]["Name"].ToString() + "价：</td><td><input type=\"text\"  name=\"txtPro_RatingDiscount\" id=\"txtPro_RatingDiscount" + i + "\" value='" + Prices + "'  Class=\"short_input\"  tip=\"为空表示价格按照等级的默认折扣来计算，也可以直接输入会员可以享受的价格\" validatetype=\"ifisfloat\" warning=\"选填\" error=\"该项为必须为数字\"/><input id=\"RatingID\" name=\"RatingID\" type=\"hidden\" value=\"" + dt.Rows[i]["Id"].ToString() + "\" /></td><td><div id='txtPro_RatingDiscount" + i + "Tip' ></div></td></tr>");
                    }
                    else
                    {
                        shtml.Append("<tr><td  class=\"form_table_input_info\">" + dt.Rows[i]["Name"].ToString() + "价：</td><td><input type=\"text\"  name=\"txtPro_RatingDiscount\" id=\"txtPro_RatingDiscount" + i + "\"  Class=\"short_input\"  tip=\"为空表示价格按照等级的默认折扣来计算，也可以直接输入会员可以享受的价格\" validatetype=\"ifisfloat\" warning=\"选填\" error=\"该项为必须为数字\"/><input id=\"RatingID\" name=\"RatingID\" type=\"hidden\" value=\"" + dt.Rows[i]["Id"].ToString() + "\" /></td><td><div id='txtPro_RatingDiscount" + i + "Tip' ></div></td></tr>");
                    }
                }
                //shtml.Append("</table>");
                restr = shtml.ToString();
            }
            else
            {
                restr = "";
            }
            return restr;
        }
        #endregion

        #region 加载扩展属性
        /// <summary>
        /// 修改加载扩展属性
        /// </summary>
        /// <param name="cID">商品分类ID</param>
        /// <param name="pID">扩展属性值数组</param>
        private string bindProperty(string cid, string propertyValue)
        {
            StringBuilder shtml = new StringBuilder();
            shtml.Append("<table  class=\"form_table_input\" border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
            try
            {
                YXShop.BLL.Product.ProductPropery bll = new YXShop.BLL.Product.ProductPropery();
                DataTable dt = bll.GetProperty(cid);
                if (dt.Rows.Count > 0)
                {
                    try
                    {

                        string[] value = null;
                        if (!string.IsNullOrEmpty(propertyValue))
                        {
                            value = propertyValue.Split('|');
                        }
                        #region 循环扩展属性的类型（单选，下拉列表，多选，单行文本和多行文本）和可选值
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string[] temp = null;
                            if (value != null)
                            {
                                temp = value[i].Split(',');
                            }
                            else
                            {
                                temp = "0,0".Split(',');
                            }
                            string sff = dt.Rows[i]["type"].ToString();
                            switch (Convert.ToInt32(dt.Rows[i]["type"].ToString()))
                            {
                                case 1:
                                    #region 从下拉列表中选择
                                    shtml.Append("<tr>");
                                    shtml.Append("<td class=\"form_table_input_info\">");
                                    shtml.Append(dt.Rows[i]["filed"].ToString() + "：");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<select name=\"" + dt.Rows[i]["id"].ToString() + "\" id=\"" + dt.Rows[i]["id"].ToString() + "\">");
                                    shtml.Append("<option value='' selected=\"selected\">--请选择" + dt.Rows[i]["filed"].ToString() + "--</option>");
                                    foreach (string s in dt.Rows[i]["datavalue"].ToString().Split('\n'))
                                    {
                                        shtml.Append("<option value=\"" + s + "\"");
                                        if (temp[0] == dt.Rows[i]["id"].ToString() && temp[1] == s)
                                        {
                                            shtml.Append(" selected=\"selected\" ");
                                        }
                                        shtml.Append(">" + s + "</option>");
                                    }
                                    shtml.Append("</select>");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<input type=\"hidden\" name=\"ProPropertyID\" value=\"" + dt.Rows[i]["id"].ToString() + "\" />");
                                    shtml.Append("</td>");
                                    shtml.Append("</tr>");
                                    break;
                                    #endregion
                                case 2:
                                    #region 单选
                                    shtml.Append("<tr>");
                                    shtml.Append("<td class=\"form_table_input_info\">");
                                    shtml.Append(dt.Rows[i]["filed"].ToString() + "：");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    foreach (string s in dt.Rows[i]["datavalue"].ToString().Split('\n'))
                                    {
                                        shtml.Append("<input type=\"radio\" name=\"" + dt.Rows[i]["id"].ToString() + "\" value=\"" + s + "\"");
                                        for (int k = 1; k < temp.Length; k++)
                                        {
                                            if (temp[0] == dt.Rows[i]["id"].ToString() && temp[k] == s)
                                            {
                                                shtml.Append(" checked=\"checked\" ");
                                                break;
                                            }
                                        }
                                        shtml.Append(" />" + s + "");
                                    }

                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<input type=\"hidden\" name=\"ProPropertyID\" value=\"" + dt.Rows[i]["id"].ToString() + "\" />");
                                    shtml.Append("</td>");
                                    shtml.Append("</tr>");
                                    break;
                                    #endregion
                                case 3:
                                    #region 多选
                                    shtml.Append("<tr>");
                                    shtml.Append("<td class=\"form_table_input_info\">");
                                    shtml.Append(dt.Rows[i]["filed"].ToString() + "：");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    foreach (string s in dt.Rows[i]["datavalue"].ToString().Split('\n'))
                                    {
                                        shtml.Append("<input type=\"checkbox\" name=\"" + dt.Rows[i]["id"].ToString() + "\" value=\"" + s + "\"");
                                        for (int k = 1; k < temp.Length; k++)
                                        {
                                            if (temp[0] == dt.Rows[i]["id"].ToString() && temp[k].Equals(s))
                                            {
                                                shtml.Append(" checked=\"checked\" ");
                                            }
                                        }

                                        shtml.Append(" />" + s + "");

                                    }
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<input type=\"hidden\" name=\"ProPropertyID\" value=\"" + dt.Rows[i]["id"].ToString() + "\" />");
                                    shtml.Append("</td>");
                                    shtml.Append("</tr>");
                                    break;
                                    #endregion
                                case 4:
                                    #region 单行文本
                                    shtml.Append("<tr>");
                                    shtml.Append("<td class=\"form_table_input_info\">");
                                    shtml.Append(dt.Rows[i]["filed"].ToString() + "：");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<input type=\"text\" id=\"" + dt.Rows[i]["id"].ToString() + "\" name=\"" + dt.Rows[i]["id"].ToString() + "\"");
                                    if (temp[0] == dt.Rows[i]["id"].ToString())
                                    {
                                        shtml.Append(" value=\"" + temp[1] + "\" ");
                                    }
                                    if (dt.Rows[i]["isrequire"].ToString() == "1")
                                    {
                                        shtml.Append(" tip=\"请输入" + dt.Rows[i]["filed"].ToString() + "\" validatetype=\"isnull\" warning=\"必填\" error=\"该项为必填项\" />");
                                    }
                                    else
                                    {
                                        shtml.Append("  />");
                                    }
                                    shtml.Append("</td>");
                                    shtml.Append("<td><input type=\"hidden\" name=\"ProPropertyID\" value=\"" + dt.Rows[i]["id"].ToString() + "\" /><div id=\"" + dt.Rows[i]["id"].ToString() + "Tip\"></div>");
                                    shtml.Append("</tr>");
                                    break;
                                    #endregion
                                case 5:
                                    #region 多行文本
                                    string strValue = string.Empty;
                                    shtml.Append("<tr>");
                                    shtml.Append("<td class=\"form_table_input_info\">");
                                    shtml.Append(dt.Rows[i]["filed"].ToString() + "：");
                                    shtml.Append("</td>");
                                    shtml.Append("<td>");
                                    shtml.Append("<textarea name=\"" + dt.Rows[i]["id"].ToString() + "\" id=\"" + dt.Rows[i]["id"].ToString() + "\" cols=\"23\" rows=\"6\"");

                                    if (temp[0] == dt.Rows[i]["id"].ToString())
                                    {
                                        strValue = temp[1];
                                    }
                                    if (dt.Rows[i]["isrequire"].ToString() == "1")
                                    {
                                        shtml.Append(" tip=\"请输入" + dt.Rows[i]["filed"].ToString() + "\" validatetype=\"isnull\" warning=\"必填\" error=\"该项为必填项\"");
                                    }
                                    shtml.Append(">");
                                    if (!string.IsNullOrEmpty(strValue))
                                    {
                                        shtml.Append(strValue);
                                    }
                                    shtml.Append("</textarea>");
                                    shtml.Append("</td>");
                                    shtml.Append("<td><input type=\"hidden\" name=\"ProPropertyID\" value=\"" + dt.Rows[i]["id"].ToString() + "\" /><div id=\"" + dt.Rows[i]["id"].ToString() + "Tip\"></div>");
                                    shtml.Append("</tr>");
                                    break;
                                    #endregion
                                default:
                                    break;
                            }

                        }
                        #endregion

                    }
                    catch (Exception ex)
                    {
                        shtml.Append("<tr><td>查询扩展属性时出错，详细信息：" + ex.ToString() + "</td></tr>");
                    }
                }
                else
                {
                    shtml.Append("<tr><td>该商品没有扩展属性" + "</td></tr>");
                }
            }
            catch (Exception ex)
            {
                shtml.Append("<tr><td>程序错误，详细信息" + ex.ToString() + "</td></tr>");
            }
            shtml.Append("</table>");
            return shtml.ToString();
        }


        #endregion

        #region 绑定商品相册
        protected void bindAlbum(int productid)
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            YXShop.BLL.Product.ProductAlbum pabll = new YXShop.BLL.Product.ProductAlbum();
            DataTable dt = pabll.GetProAlbumAll(productid,-1,0);
            StringBuilder str = new StringBuilder();
            int j = 1;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                str.Append("<td align='center'><img width=\"100px\" height=\"100px\" src=\"" + sp.DummyPaht + dt.Rows[i]["originaladdress"].ToString() + "\"/><br/><br/><span onclick=\"DelProAlbum(" + dt.Rows[i]["id"].ToString() + ");\"  style=\"cursor:hand;width:45px\" >删除</span></td>");
                if (j % 6 == 0)
                {
                    str.Append("</tr><tr>");
                }
                j++;
            }

            this.litaAlbum.Text = str.ToString();
        }
        #endregion

        #region 删除相册图片
        private void DelAlbum(string Alubmid)
        {
            YXShop.BLL.Product.ProductAlbum pabll = new YXShop.BLL.Product.ProductAlbum();
            pabll.Delete(Convert.ToInt32(Alubmid));
            Response.Write("ok");
        }
        #endregion

        #region 搜索绑定相关商品
        private void SearchRelatedProduct(string Name)
        {
            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            ChangeHope.DataBase.DataByPage dbp = bll.GetList(" [order by] pro_ID asc", 50, " and pro_Name like '%" + Name + "%'");
            StringBuilder select = new StringBuilder();
            select.Append("<select size=\"14\" id=\"selPro_RelatingProID\" style=\"width: 98%\">");
            if (dbp.DataReader != null)
            {
                while (dbp.DataReader.Read())
                {
                    select.Append("<option value=\"" + dbp.DataReader["pro_ID"].ToString() + "\">" + dbp.DataReader["pro_Name"].ToString() + "</option>");
                }
            }
            select.Append("</select>");
            Response.Write(select.ToString());
        }
        #endregion

        #region 修改商品绑定相关商品
        protected void RelateProductBindInfo(string RelationProductID)
        {
            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            ChangeHope.DataBase.DataByPage dbp = bll.GetList(" [order by] pro_ID asc", 50, " and pro_ID in (" + RelationProductID + ")");
            StringBuilder selectsb = new StringBuilder();
            selectsb.Append("<select name=\"selPro_RelatingProIDSelect\" size=\"14\" multiple=\"multiple\" style=\"width: 98%\">");
            if (dbp.DataReader != null)
            {
                while (dbp.DataReader.Read())
                {
                    selectsb.Append("<option value=\"" + dbp.DataReader["pro_ID"].ToString() + "\" selected>" + dbp.DataReader["pro_Name"].ToString() + "</option>");
                }
            }
            selectsb.Append("</select>");
            this.ltRelatingProductSelected.Text = selectsb.ToString();
        }
        #endregion

        #region 搜索绑定相关文章
        private void SearchRelatedArticle(string Name)
        {
            YXShop.BLL.SystemInfo.Article bll = new YXShop.BLL.SystemInfo.Article();
            ChangeHope.DataBase.DataByPage dbp = bll.GetList(" and Title like '%" + Name + "%'");
            StringBuilder select = new StringBuilder();
            select.Append("<select size=\"14\" id=\"selPro_RelatingArtID\" multiple=\"multiple\" name=\"selPro_RelatingArtID\" style=\"width: 98%\">");
            if (dbp.DataReader != null)
            {
                while (dbp.DataReader.Read())
                {
                    select.Append("<option value=\"" + dbp.DataReader["Id"].ToString() + "\">" + dbp.DataReader["Title"].ToString() + "</option>");
                }
            }
            select.Append("</select>");
            Response.Write(select.ToString());
        }
        #endregion

        #region 修改商品绑定相关文章
        protected void RelateArticleBindInfo(string RelationArticleID)
        {
            YXShop.BLL.SystemInfo.Article bll = new YXShop.BLL.SystemInfo.Article();
            ChangeHope.DataBase.DataByPage dbp = bll.GetList(" and Id in (" + RelationArticleID + ")");
            StringBuilder selectsb = new StringBuilder();
            selectsb.Append("<select name=\"selPro_RelatingArtIDSelect\" size=\"14\" multiple=\"multiple\" style=\"width: 98%\">");
            if (dbp.DataReader != null)
            {
                while (dbp.DataReader.Read())
                {
                    selectsb.Append("<option value=\"" + dbp.DataReader["Id"].ToString() + "\" selected>" + dbp.DataReader["Title"].ToString() + "</option>");
                }
            }
            selectsb.Append("</select>");
            this.ltRelatingArticle.Text = selectsb.ToString();
        }
        #endregion
    }
}
